package com.yunxie.novelservice.domain.service.impl;

import com.alibaba.fastjson2.JSON;
import com.yunxie.novelservice.domain.convert.NovelDetailsBoConverter;
import com.yunxie.novelservice.domain.entity.NovelDetailsBo;
import com.yunxie.novelservice.domain.service.NovelDetailsDomainService;
import com.yunxie.novelservice.infra.basic.entity.NovelDetails;
import com.yunxie.novelservice.infra.basic.service.NovelDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class NovelDetailsDomainServiceImpl implements NovelDetailsDomainService {
    @Resource
    private NovelDetailsService novelDetailsService;
    @Override
    public NovelDetailsBo queryNovelInfo(Long id) {
        if (log.isInfoEnabled()){
            log.info("NovelDetailsDomainServiceImpl.queryNovelInfo.bo:{}", JSON.toJSON(id));
        }
        NovelDetails novelDetails = novelDetailsService.queryById(id);
        NovelDetailsBo detailsBo= NovelDetailsBoConverter.INSTANCE.convertEntityToBo(novelDetails);
        return detailsBo;
    }

    @Override
    public Boolean DeleteNovelInfo(NovelDetailsBo novelDetailsBo) {
        if (log.isInfoEnabled()){
            log.info("NovelDetailsDomainServiceImpl.DeleteNovelInfo.bo:{}",JSON.toJSON(novelDetailsBo));
        }
        boolean result = novelDetailsService.deleteById(novelDetailsBo.getDetailId());
        return result;
    }

    @Override
    public void addNovelInfo(NovelDetailsBo novelDetailsBo) {
        if (log.isInfoEnabled()){
            log.info("NovelDetailsDomainServiceImpl.addNovelInfo.bo:{}",JSON.toJSON(novelDetailsBo));
        }
        NovelDetails novelDetails = NovelDetailsBoConverter.INSTANCE.convertBoToDetails(novelDetailsBo);
        novelDetailsService.insert(novelDetails);
    }

    @Override
    public void updateNovelInfo(NovelDetailsBo novelDetailsBo) {
        if (log.isInfoEnabled()){
            log.info("NovelDetailsDomainServiceImpl.updateNovelInfo.bo:{}",JSON.toJSON(novelDetailsBo));
        }
        NovelDetails novelDetails = NovelDetailsBoConverter.INSTANCE.convertBoToDetails(novelDetailsBo);
        novelDetailsService.update(novelDetails);
    }
}
